package org.scboy.rbac.controller;

import org.scboy.common.annotation.Menu;
import org.scboy.common.annotation.Permission;
import org.scboy.common.request.Result;
import org.scboy.rbac.service.OrgRoleService;
import org.scboy.utils.entitys.coobi.Model;
import org.scboy.utils.entitys.coobi.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/rbac/orgrole/")
@Menu("权限管理系统.组织角色管理")
public class OrgRoleServiceController {
	
	@Autowired
	OrgRoleService service;
	
	@PostMapping("page")
	@Permission("分页查询组织角色")
	public Result page(@RequestBody Model params) {
		Page page=service.page(params);
		return Result.Success(page);
	}
	
	@PostMapping("list")
	@Permission("查询组织角色列表")
	public Result list(@RequestBody Model params) {
		return Result.Success(service.list(params), "");
	}

	@PostMapping("add")
	@Permission("新增组织角色")
	public Result add(String code,String orgId){
		boolean check=service.add(code,orgId);
		if(check) {
			return Result.Success("RBAC_ORG_ROLE_ADD_SUCCESS");
		}else {
			return Result.Error("RBAC_ORG_ROLE_ADD_ERROR");
		}
	}


	@PostMapping("adds")
	@Permission("新增组织角色")
	public Result adds(@RequestBody Model params){
		String orgId=params.getString("orgId");
		String [] code=params.getStringArray("code");
		if(code.length==0) {
			return Result.Error("RBAC_ORG_ROLE_ADDS_ERROR");
		}
		boolean check=service.add(code,orgId);
		if(check) {
			return Result.Success("RBAC_ORG_ROLE_ADDS_SUCCESS");
		}else {
			return Result.Error("RBAC_ORG_ROLE_ADDS_ERROR");
		}
	}
	
	@DeleteMapping("delete")
	@Permission("删除组织角色")
	public Result delete(String id){
		boolean check=service.delete(id);
		if(check) {
			return Result.Success("RBAC_ORG_ROLE_DELETE_SUCCESS");
		}else {
			return Result.Error("RBAC_ORG_ROLE_DELETE_ERROR");
		}
	}

}
